#pragma once

#include "precompiled.h"

/*	File : Common.h
 *
 */

// Declare some errors/exits for clarity.
static const int MYEXIT_SUCCESS = 0;
static const int MYEXIT_FAILED_OPENWINDOW = 1;
static const int MYEXIT_FAILED_LINKSHADERS = 2;
static const int MYEXIT_MODEL_NOT_TRIANGLES = 3;
static const int MYEXIT_FAILED_CONVERTIMAGE = 4;
static const int MYEXIT_DEVIL_NOT_INITIALIZED = 5;

/************************************************************************/
/* Output an error.                                                        
/************************************************************************/
inline void printError(char const * hdr,char const * err){
	std::cout << hdr << ": " << err << std::endl;
}

//Define this somewhere in your header file
#define BUFFER_OFFSET(i) ((char *)NULL + (i))


/************************************************************************/
/* Directions.                                                       
/************************************************************************/
#define FLOAT_MIN numeric_limits<float>::min()
#define FLOAT_MAX numeric_limits<float>::max()


/************************************************************************/
/* Directions.                                                       
/************************************************************************/
const static glm::vec3 UP(0.0f,1.0f,0.0f);
const static glm::vec3 RIGHT(1.0f,0.0f,0.0f);
const static glm::vec3 FORWARD(0.0f,0.0f,1.0f);


/************************************************************************/
/* Transformations.                                                     
/************************************************************************/
typedef struct{
	glm::vec4 _position;
	glm::vec3 _translation;
	glm::vec3 _rotation;
	glm::vec3 _scale;
	glm::mat4 _model;
}TransformationCore;

const static float GLM_ROTATE_AMOUNT = 1.0f;//0.4f;


/************************************************************************/
/* Macros.                                                     
/************************************************************************/
// Get the larger of 2 supplied values.
#define THEMAX(a,b)( (a>b)?a:b )

// Get the lesser of 2 supplied values.
#define THEMIN(a,b)( (a<b)?a:b )

// Bound a value between a minimum_a and maximum_b.
#define THECLAMP(val,a,b)( THEMIN( (THEMAX(val,a)), b )  )


// Convert to a wchar_t*
inline wchar_t* char_to_wchart(const char* orig){

	size_t origsize = strlen(orig) + 1;
	const size_t newsize = 100;
	size_t convertedChars = 0;
	wchar_t wcstring[newsize];
	mbstowcs_s(&convertedChars, wcstring, origsize, orig, _TRUNCATE);
	wcscat_s(wcstring, L" (wchar_t *)");
	//wcout << wcstring << endl;
	return wcstring;
}

